package com.usian.controller;

import com.usian.pojo.Total;
import com.usian.pojo.User;
import com.usian.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
@RequestMapping("/user")
@Controller
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/findList")
    public String findList(Model model,Total total){
        List<Total> list = userService.findList(total);
        model.addAttribute("list",list);
        return "findList";
    }

    @RequestMapping("/caozuo")
    public String caozuo(Model model,Total total){
        List<Total> list = userService.findList(total);
        model.addAttribute("list",list);
        return "caozuo";
    }

    @RequestMapping("ad")
    public String ad(){
        return "Add";
    }

    @RequestMapping("Add")
    public String Add(Total user){
        userService.Add(user);
        return "redirect:/user/findList";
    }

    @RequestMapping("del")
    public String del(Integer id){
        userService.del(id);
        return "redirect:findList";
    }

    @RequestMapping("upd")
    public String upd(Integer id,Model model){
        Total user= userService.upd(id);
        model.addAttribute("user" ,user);
        return "update";
    }

    @RequestMapping("update")
    public String update(Total user){
        userService.update(user);
        return "redirect:/user/findList";
    }
}
